package com.bll.impl.activityAction;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.ActivityBean;
import com.bll.Action;
import com.dao.ActivityDao;
import com.dao.Page;

public class ShowActivityAction implements Action{
	public String execute(HttpServletRequest request,HttpServletResponse response) {
        
		int userId=Integer.parseInt(request.getSession().getAttribute("userId").toString());
		String lujing=request.getParameter("lujing");
		ActivityDao dao=new ActivityDao();
		List<ActivityBean> list=dao.SelectAll(userId);
		
		int totalRows=list.size();
		int rowsPerPage=5;
	    int currentPage=1;
	    int totalPages=Page.computer(totalRows, rowsPerPage);
		if(request.getParameter("currentPage")!=null){
			currentPage=Integer.parseInt(request.getParameter("currentPage"));
			if(currentPage<1){
			
				currentPage=1;
			}else if(currentPage>totalPages){
			
				currentPage=totalPages;
			}
		}
		int currentRows=(currentPage-1)*rowsPerPage;
//		if(request.getParameter("currentRows")!=null){
//			currentRows=Integer.parseInt(request.getParameter("currentRows"));
//		}
		//System.out.println("currenet:"+currentRows);
	    
		request.setAttribute("currentPage", currentPage);
	    request.setAttribute("totalPages", totalPages);
	    List<ActivityBean> beans=dao.selectPages(currentRows, rowsPerPage, userId);
		
		request.setAttribute("beans", beans);
		
//		int userId=Integer.parseInt(request.getSession().getAttribute("userId").toString());
//		String lujing=request.getParameter("lujing");
//		ActivityDao dao=new ActivityDao();
//		List<ActivityBean> beans=dao.SelectAll(userId);
//		request.setAttribute("beans", beans);
		
		return lujing;
	}
}
